package com.econ.powercloud.ems.common.enums;

import java.util.Arrays;

public enum AnalogType implements EnumMethod {

    OTHER_TYPE(1,"其他类型"),
    POWER(2, "基本类型-功率"),
    FREQUENCY(3,"基本类型-频率"),
    VOLTAGE(4,"基本类型-电压"),
    ELECTRICITY(5,"基本类型-电流"),
    OTHER(6,"基本类型-其他"),
    DC_VOLTAGE(7,"直流电压"),
    FAULT_DC_VOLTAGE(8,"故障直流电压"),
    ALERT_DC_VOLTAGE(9,"报警直流电压"),
    HISTORY_ALERT(10,"历史报警"),
    CALCULATION(11,"计算"),
    OTA_UPGRADE_PROGRESS(12,"OTA升级进度"),
    OTA_FIRMWARE_VERSION(13,"OTA固件版本"),
    TEMPERATURE(14,"温度"),
    COMPOSITE_CALCULATION_RESULTS(15,"复合计算结果"),
    PROTECT_CONSTANT_VALUE(16,"保护定值"),;

    private Integer code;
    private String desc;

    @Override
    public Integer getCode() {
        return code;
    }

    @Override
    public String getDesc() {
        return desc;
    }


    AnalogType(int code, String desc){
        this.code=code;
        this.desc=desc;
    }

    public static AnalogType fromCode(Integer code) {
        return Arrays.stream(AnalogType.values()).filter(it -> it.getCode().equals(code)).findFirst().orElse(OTHER_TYPE);
    }

    public static String getDescFromCode(Integer code) {
        for(AnalogType type: AnalogType.values()){
            if(type.getCode().equals(code)){
                return type.getDesc();
            }
        }
        return null;
    }

    public static AnalogType fromName(String name){
        for(AnalogType type: AnalogType.values()){
            if(type.getDesc().equals(name)){
                return type;
            }
        }
        return null;
    }

}
